<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- 兼容性 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>基础设置-设置预警信息</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
            background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div class="title-list mb-20"><span class="title-listbg"></span><span>预警信息</span></div>
<div class="container">
    <div class="mini-clearfix mb-10">
        <div class="mini-col-6 mini-col-sm-3">
            <a class="plan-btn mR-20"  onclick="list.addOrEdit('new')"><span class="add-bg"></span>新增</a>
        </div>
    </div>
</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"  url="/EarlyWarning/listByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id" multiSelect="true" showEmptyText="true" emptyText="暂无数据" alwaysShowEmptyText="true">
        <div property="columns">
            <!--<div type="checkcolumn" headerAlign="center" align="center"></div>-->
            <div type="indexcolumn" headerAlign="center" align="center">编号</div>
            <div field="workDay" width="120" headerAlign="center" align="left" allowSort="false">总工期</div>
            <div field="schedule" width="120" headerAlign="center" align="center" allowSort="false">进度</div>
            <div field="status" width="120" headerAlign="center" align="center" allowSort="false">状态</div>
            <div field="createName" width="120" headerAlign="center" align="center" allowSort="false">创建人</div>
            <div field="createDate" width="120" headerAlign="center" align="center" allowSort="false" renderer="ondayRenderer">创建时间</div>
            <div name="action" width="200" headerAlign="center" align="center">操作</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //list.init();
    var grid;
    var list = {
        //页面初始化
        init: function() {
            mini.parse();
            grid = mini.get("datagrid1");
            grid.load();
            grid.on("drawcell", function (e) {
                console.log(e)
                var column = e.column;
                var record = e.record;
                if(column.field=="workDay"){
                    e.cellHtml = '大于等于'+e.row.workDayLeast+'%'+'小于'+e.row.workDayMax+'%';
                }
                if(column.field=="status"){
                	if(record.status == 1){
                		e.cellHtml =  "风险"
                	}else if(record.status == 2){
                		e.cellHtml = "失控"
                	}
                }
                if(column.field=="schedule"){
                    e.cellHtml = '小于'+e.row.schedule+'%';
                }
                if (column.name == "action") {
                    e.cellHtml = '<a class="revise-botton" href="javascript:list.addOrEdit(\''+'edit'+'\')">编辑</a><a class="del-botton btn-bd" onclick="list.remove()">删除</a>';
                }
            })
        },
        //    新增或编辑
        addOrEdit: function (opt) {
            mini.open({
                url: "/dataBase/earlyWarning/new.html",
                title: (opt=="edit"?"编辑":"新增")+"预警设置", width: 1100, height: 400,
                onload: function () {
                    if(opt=="edit"){
                        var row = grid.getSelected();
                        var data = {"id": row.id,"state":opt};
                    }else{
                        var data = {"state":opt};
                    }
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        },
        //    查看
        view: function(){
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "/dataBase/earlyWarning/view.html",
                    title: "预警设置", width: 1100, height: 400,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {"id": row.id};
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        },
        //    查询
        search: function () {
            var data = {
                "name": mini.get("name").getValue(),
                "affiliatedCompanyId": mini.get("affiliatedCompanyId").getValue(),
//            "provinceId": mini.get("provinceCombo").getValue() ? mini.get("provinceCombo").getValue() : 0,
                "cityId": mini.get("cityCombo").getValue(),
//            "regionId": mini.get("regionCombo").getValue() ? mini.get("regionCombo").getValue() : 0,
            };
            grid.load(data);
        },
        //重置
        reset:function(){
            var form = new mini.Form("qForm");
            form.reset();
            grid.load()
        },
        //    删除
        remove: function () {
            var row = grid.getSelected();
            if (row) {
                mini.confirm("确定删除选中记录？","确定",function (action) {
                    if(action=="ok"){
                        $.ajax({
                            url: "/EarlyWarning/del",
                            type : "post",
                            data:{"id":row.id},
                            success: function (text) {
                                if (text.state) {
                                    grid.reload();
                                } else {
                                    mini.showMessageBox({
                                        showModal: false,
                                        width: 250,
                                        title: "提示",
                                        iconCls: "mini-messagebox-warning",
                                        message: text.message,
                                    });

                                }
                            },
                            error:function (errorMsg) {
                                common.prompt(errorMsg.message);
                            }
                        });
                    }
                });
            } else {
                alert("请选中一条记录");
            }
        }
    };
    list.init();
</script>
</body>
</html>